﻿<extend name="Common/public"/>

<block name="content">
<title>添加产品分类</title>
</head>
<body>
<div class="pd-20">
	<if condition='!empty($cat_id)'><a href="{:U('categoryAdd',array('add'=>1,'cat_id'=>$cat_id))}" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加子分类</a></span></if>
  <form action="" method="post" class="form form-horizontal" id="form-user-add">
  <div class="row cl">
      <label class="form-label col-2">上级分类名称：</label>
      <div class="formControls col-5">
        <input type="text" class="input-text" value="<if condition='empty($cat_id)'>第一级分类<else/>{$p_name}</if>" placeholder="" id="user-name" name="cat_name" readonly="readonly">
      </div>
      <div class="col-5"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>分类名称：</label>
      <div class="formControls col-5">
        <input type="text" class="input-text" value="{$cat['cat_name']}" placeholder="" id="user-name" name="cat_name">
      </div>
      <div class="col-5"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2">排序：</label>
      <div class="formControls col-5">
        <input type="text" class="input-text" value="<if condition='empty($cat)'>0<else/>{$cat['sort']}</if>" placeholder="" id="user-name" name="sort">
      </div>
      <div class="col-5"> </div>
    </div>
    
    <div class="row cl">
      <div class="col-9 col-offset-2">
      	<if condition="!empty($cat)">
      	<input type="hidden" name="cat_id" value="{$cat_id}"/>
      	</if>
      	<if condition="$_GET['add'] == 1">
      	<input type="hidden" name="pid" value="{$cat_id}"/>
      	</if>
        <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;<empty name='cat'>添加栏目<else/>修改栏目</empty>&nbsp;&nbsp;">
        <if condition='!empty($cat)'><a class="btn btn-danger radius" onclick="member_del('{:U('categoryDel',array('add'=>1,'cat_id'=>$cat_id))}')"><i class="Hui-iconfont">&#xe6e2;</i> 删除分类</a></span></if>
      </div>
    </div>
  </form>
</div>
</div> 

<include file="Common/js"/>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	var form = $("#form-user-add").Validform({
		url:'{:U()}',
		ajaxPost:true,
		callback:function(data){
			$.Hidemsg();
			if(data.status == 1){ // 成功
				
				$.Showmsg('成功');
				setTimeout(function (){
					$.Hidemsg();
					parent.location.reload();
				},1000);
			}else { // 失败
				$.Showmsg(data.msg);
				setTimeout(function (){
					$.Hidemsg();
				},1000);
			}
		}
	});
});

function member_del(url){
	layer.confirm('确认要删除吗？',function(index){
		
		$.post(url,{},function(data){
			if(data.status == 1){
				layer.msg('删除成功!',{icon:6,time:1000});
				setTimeout(function(){
					parent.location.reload();
				},1000);
			}else {
				layer.msg('删除失败!',{icon:5,time:1000});
			}
			
		})
	});
}
</script>
</body>
</block>